// const compose = (...fns) => {
//     return (...args) => {
//         let ret = fns[0](...args)
//         for (let i = 1; i < fns.length; i++) {
//             ret = fns[i](ret)
//         }
//         return ret
//     }
// }

const compose = (...fns) => {
    return (...args) => {
        let init = fns[0](...args)
        let arr = fns.slice(1)
        let ret = arr.reduce((pre, curr) => curr(pre), init)
        return ret
    }
}

const a = (x, y) => x + y  // 2 + 3 = 5
const b = x => x + 1       // 5 + 1 = 6 
const c = x => x * 2       // 6 * 2 = 12
const d = x => x - 1       // 12 - 1 = 11

const abcd = compose(a, b, c, d)

console.log(abcd(2, 3));